package com.platform.web.controller.module;

import java.util.List;
import com.platform.framework.util.ShiroUtils;
import com.platform.module.domain.BaseFactory;
import com.platform.module.domain.BaseRoomTemp;
import com.platform.module.service.IBaseFactoryService;
import com.platform.system.service.ISysDictDataService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.platform.common.annotation.Log;
import com.platform.common.enums.BusinessType;
import com.platform.module.domain.BaseRoomTemp;
import com.platform.module.service.IBaseRoomTempService;
import com.platform.common.core.controller.BaseController;
import com.platform.common.core.domain.AjaxResult;
import com.platform.common.utils.poi.ExcelUtil;
import com.platform.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 室温采集器资料Controller
 * 
 * @author wangqi
 * @date 2020-07-28
 */
@Controller
@RequestMapping("/module/temp")
public class BaseRoomTempController extends BaseController
{
    private String prefix = "module/temp";

    @Autowired
    private IBaseRoomTempService baseRoomTempService;

    @Autowired
    private IBaseFactoryService baseFactoryService;

    @RequiresPermissions("module:temp:view")
    @GetMapping()
    public String temp()
    {
        return prefix + "/temp";
    }

    /**
     * 查询室温采集器资料列表
     */
    @RequiresPermissions("module:temp:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BaseRoomTemp baseRoomTemp)
    {
        startPage();
        List<BaseRoomTemp> list = baseRoomTempService.selectBaseRoomTempList(baseRoomTemp);
        return getDataTable(list);
    }

    /**
     * 新增室温采集器资料
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        List<BaseFactory> factorys = baseFactoryService.list();
        mmap.put("factorys", factorys);
        return prefix + "/add";
    }

    /**
     * 新增保存室温采集器资料
     */
    @RequiresPermissions("module:temp:add")
    @Log(title = "室温采集器资料", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BaseRoomTemp baseRoomTemp)
    {
        baseRoomTemp.setCreateBy(ShiroUtils.getLoginName());
        return toAjax(baseRoomTempService.insertBaseRoomTemp(baseRoomTemp));
    }

    /**
     * 修改室温采集器资料
     */
    @GetMapping("/edit/{baseId}")
    public String edit(@PathVariable("baseId") Long baseId, ModelMap mmap)
    {
        List<BaseFactory> factorys = baseFactoryService.list();
        mmap.put("factorys", factorys);
        BaseRoomTemp baseRoomTemp = baseRoomTempService.getById(baseId);
        mmap.put("baseRoomTemp", baseRoomTemp);
        return prefix + "/edit";
    }

    /**
     * 修改保存室温采集器资料
     */
    @RequiresPermissions("module:temp:edit")
    @Log(title = "室温采集器资料", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BaseRoomTemp baseRoomTemp)
    {
        baseRoomTemp.setUpdateBy(ShiroUtils.getLoginName());
        return toAjax(baseRoomTempService.updateBaseRoomTemp(baseRoomTemp));
    }

    /**
     * 删除室温采集器资料
     */
    @RequiresPermissions("module:temp:remove")
    @Log(title = "室温采集器资料", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(baseRoomTempService.deleteBaseRoomTempByIds(ids));
    }

    /**
     * 校验厂商代码
     */
    @PostMapping("/checkRoomTempCodeUnique")
    @ResponseBody
    public String checkRoomTempCodeUnique(BaseRoomTemp baseRoomTemp)
    {
        return baseRoomTempService.checkRoomTempCodeUnique(baseRoomTemp);
    }
}
